// custom-tab-bar/index.js
import { store } from '../store/store'
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
Component({
  behaviors: [storeBindingsBehavior],
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    dataTab: [
      {id:1,title:'首页',img:'../images/nav/main1.png',activeImg:'/images/nav/main.png',info:0,url:'/pages/index/index',icon:'wap-home-o'},
      {id:2,title:'地图',img:'/images/nav/ditu1.png',activeImg:'/images/nav/ditu.png',info:0,url:'/pages/mapsearch/mapsearch',icon:'map-marked'},
      {id: false},
      {id:3,title:'订单',img:'/images/nav/order1.png',activeImg:'/images/nav/order.png',info:0,url:'/pages/scen/scen',icon:'orders-o'},
      {id:4,title:'我的',img:'/images/nav/wo1.png',activeImg:'/images/nav/wo.png',info:0,url:'/pages/users/users',icon:'friends-o'},
      
    ]
  },
  storeBindings: {
    store,
    fields: {
      numA: 'numA',
      carsNum: 'carsNum',
      tabBarActive: 'tabBarActive'
    },
    actions: {
      updateActives: 'updateActives'
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goUrl(event){
      console.log('event',event)
      let url = event.currentTarget.dataset.url
      wx.switchTab({
        url: url,
      })
    },
      //扫码
  userScen() {
    // 允许从相机和相册扫码
    wx.scanCode({
      success(res) {
        console.log(res)
        let sn = res.result;
        let index = sn.lastIndexOf("\=");
        sn = sn.substring(index + 1, sn.length);
        console.log(res.result)
        wx.navigateTo({
          url: '/subpage/pages/charge/charge?sn=' + sn,
        })
      }
    })
  },
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.updateActives(event.detail)
      wx.switchTab({
        url: this.data.dataTab[event.detail].url,
      })
    },
  },
  observers: {
    'carsNum' : function (val) {
      this.setData({
        'dataTab[2].info': val
      })
    }
  },
})
